package model;

public class Course {
    private String code;    // 课程编号
    private String name;    // 课程名称
    private int credit;     // 学分

    public Course(String code, String name, int credit) {
        this.code = code;
        this.name = name;
        this.credit = credit;
    }

    // Getter和Setter方法
    public String getCode() { return code; }
    public String getName() { return name; }
    public int getCredit() { return credit; }

    public void setName(String name) { this.name = name; }
    public void setCredit(int credit) { this.credit = credit; }

    @Override
    public String toString() {
        return code + "," + name + "," + credit;
    }

    // 从字符串解析Course对象
    public static Course fromString(String data) {
        String[] parts = data.split(",");
        if (parts.length == 3) {
            return new Course(parts[0], parts[1], Integer.parseInt(parts[2]));
        }
        return null;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null || getClass() != obj.getClass()) return false;
        Course course = (Course) obj;
        return code.equals(course.code);
    }

    @Override
    public int hashCode() {
        return code.hashCode();
    }
}